package com.zl.singleton;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @author zengle
 * @create 2021-07-01 15:32
 */
public class Singleton7 {
    private static final AtomicReference<Singleton7> SINGLETON_7_ATOMIC_REFERENCE =
            new AtomicReference<>();

    private Singleton7() {
    }

    public static Singleton7 getInstance() {
        for (; ; ) {
            Singleton7 singleton7 = SINGLETON_7_ATOMIC_REFERENCE.get();
            if (singleton7 != null) {
                return singleton7;
            }
            singleton7 = new Singleton7();
            if (SINGLETON_7_ATOMIC_REFERENCE.compareAndSet(null, singleton7)) {
                return singleton7;
            }
        }
    }
}
